﻿using System;
using Microsoft.EntityFrameworkCore;
using TestCluster.usermodels;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace TestCluster
{
    /// <summary>
    /// 
    /// </summary>
    public static class TestClusterDbContextModelCreatingExtensions
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="optionsAction"></param>
        public static void ConfigureTestCluster(
            this ModelBuilder builder,
            Action<TestClusterModelBuilderConfigurationOptions> optionsAction = null)
        {


            Check.NotNull(builder, nameof(builder));

            var options = new TestClusterModelBuilderConfigurationOptions(
                TestClusterDbProperties.DbTablePrefix,
                TestClusterDbProperties.DbSchema
            );

            optionsAction?.Invoke(options);

            /* Configure all entities here. Example:

            builder.Entity<Question>(b =>
            {
                //Configure table & schema name
                b.ToTable(options.TablePrefix + "Questions", options.Schema);
            
                b.ConfigureByConvention();
            
                //Properties
                b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
                
                //Relations
                b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);

                //Indexes
                b.HasIndex(q => q.CreationTime);
            });
            */
            // *UserInfo*
            builder.Entity<UserInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "UserInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *RoleInfo*
            builder.Entity<RoleInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "RoleInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *GradeInfo*
            builder.Entity<GradeInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "GradeInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *GradeRole*
            builder.Entity<GradeRole>(b =>
            {
                b.ToTable(options.TablePrefix + "GradeRole", options.Schema);
                b.ConfigureByConvention();
            });

            // *PartInfo*
            builder.Entity<PartInfo>(b =>
            {
                b.ToTable(options.TablePrefix + "PartInfo", options.Schema);
                b.ConfigureByConvention();
            });

            // *BindUserPart*
            builder.Entity<BindUserPart>(b =>
            {
                b.ToTable(options.TablePrefix + "BindUserPart", options.Schema);
                b.ConfigureByConvention();
            });



        }
    }
}